package com.yiren.dbaa.module.practice_set.site.view.adapter;

import android.content.Context;

import com.lljjcoder.bean.CustomCityData;
import com.lljjcoder.citywheel.CustomConfig;
import com.lljjcoder.style.citycustome.CustomCityPicker;
import com.yiren.dbaa.R;
import com.yiren.dbaa.module.practice_set.site.bean.ProvinceBean;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lwb
 * @date : 2022/10/11 15:10
 * @description: 城市选择器view
 */
public class CitySelectorView {

    public static List<CustomCityData> mProvinceListData;

    /**
     * 创建城市选择器
     * @param context
     */
    public static CustomCityPicker createView(Context context) {
        CustomCityPicker mPicker = new CustomCityPicker(context);
        CustomConfig cityConfig = new CustomConfig.Builder()
                .setCityData(mProvinceListData)
                .setCityWheelType(CustomConfig.WheelType.PRO_CITY)
                .setCustomItemLayout(R.layout.item_city)//自定义item的布局
                .setCustomItemTextViewId(R.id.item_city_name_tv)
                .provinceCyclic(false)//省份滚轮是否可以循环滚动
                .cityCyclic(false)//城市滚轮是否可以循环滚动
                .build();
        mPicker.setCustomConfig(cityConfig);
        return mPicker;
    }

    public static void setCityData(List<ProvinceBean>  provinceList){
        /**
         * 自定义数据源-省份数据
         */
        mProvinceListData = new ArrayList<>();

        for (int i=0;i<provinceList.size();i++){
            CustomCityData pro = new CustomCityData(provinceList.get(i).getId(), provinceList.get(i).getName());
            List<CustomCityData> cityList = new ArrayList<>();
            if (provinceList.get(i).getCityBeanList()!=null) {
                for (int j = 0; j < provinceList.get(i).getCityBeanList().size(); j++) {
                    CustomCityData city = new CustomCityData(provinceList.get(i).getCityBeanList().get(j).getId(), provinceList.get(i).getCityBeanList().get(j).getName());
                    cityList.add(city);
                }
                if (provinceList.get(i).getCityBeanList().size() == 0){
                    CustomCityData city = new CustomCityData(pro.getId(),pro.getName());
                    cityList.add(city);
                }
            }
            pro.setList(cityList);
            mProvinceListData.add(pro);
        }
    }

}